/**
 * @作者:黎谢之
 * @创建时间：2021/7/7
 * @修改时间：2021/7/10
 */
package com.example.senior_bug.Service;

import com.example.senior_bug.ToolClass.Result;
import com.example.senior_bug.Repository.BrandRepository;
import com.example.senior_bug.Repository.GoodRepository;
import com.example.senior_bug.enm.MsgId;
import com.example.senior_bug.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GoodService {
    @Autowired
    private GoodRepository goodRepository;
    @Autowired
    private BrandRepository brandRepository;

    /*商家上架页面时需要将货物的Name转换成Id
     * 1.Param：Name(传过来的货物名字)
     * 获得货物对象的Id
     * */
    public Result GetGoodByName(String Name) {
        //判断三级分类是否存在
        if (goodRepository.existsByName(Name)) {
            return ResultUtils.success(goodRepository.findByName(Name).getId());
        } else {
            return ResultUtils.error(MsgId.GOOD_NOT_FOUND);
        }
    }
}
